﻿<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"/>

  <xsl:param name="details">false</xsl:param>
  <xsl:param name="thumbnails">false</xsl:param>
  <xsl:param name="shading">true</xsl:param>
  <xsl:param name="pageTitle">Movie Collection</xsl:param>
  <xsl:param name="includeCreationDate">true</xsl:param>

  <!-- the main template -->
  <xsl:template match="/">
    <HTML>
      <HEAD>
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <TITLE>
          <xsl:value-of select="$pageTitle"/>
        </TITLE>
      </HEAD>
      <STYLE>
        body {{
        font-family: {0};
        font-size: {1}pt;
        color: {2};
        background-color: {3};
        }}

        table {{
        font-size: {1}pt;
        }}

        .value {{
        }}

        .header {{
        font-weight: bold;
        font-size: 150%;
        text-align: left;
        padding: 2 2 2 2;
        background-color: {3};
        border: solid 1px;
        }}

        .shading {{
        background-color: #777777;
        }}

        .title {{
        font-size : 16pt;
        font-weight: bold;
        text-align: center;
        }}

        a {{
        color: {2};
        }}

        .navigation {{
        }}

        .navigationline {{
        padding: 2px 0px;
        }}

        .navlink {{
        text-align: center;
        display: inline;
        color: {2};
        font-size: {1}pt;
        font-weight : bold;
        padding-left: 5px;
        padding-right: 5px;
        }}

        .navlink#current {{
        border: solid 1px;
        }}

        .navlink a {{
        text-decoration: none;
        color: {2};
        font-size: {1}pt;
        font-weight : bold;
        }}

        .navlink a:hover {{
        text-decoration: underline;
        }}
      </STYLE>
      <BODY>
        <div align="center">
          <span class="title">
            <xsl:value-of select="$pageTitle"/>
          </span>
          <br/>
          <xsl:apply-templates select="movies/navigation"/>
          <table>
            <xsl:if test="$thumbnails = 'true'">
              <th/>
            </xsl:if>

            {4}

            <xsl:if test="$details = 'true'">
              <th/>
            </xsl:if>
            <xsl:apply-templates select="movies/movieInfo"/>
          </table>
          <xsl:if test="$includeCreationDate = 'true'">
            <br/>
            <div class="value">
              <xsl:value-of select="//@creationDate"/>
            </div>
          </xsl:if>
        </div>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="movieInfo">

    <tr>
      <xsl:if test="$shading = 'true'">
        <xsl:if test="position() mod 2 = 0">
          <xsl:attribute name="class">shading</xsl:attribute>
        </xsl:if>
      </xsl:if>

      <xsl:if test="$thumbnails = 'true'">
        <td class="value">
          <xsl:choose>
            <xsl:when test="$details = 'true'">
              <a href="details/{{id}}.html">
                <img src="images/{{id}}t.jpg" border="0"/>
              </a>
            </xsl:when>
            <xsl:otherwise>
              <a href="images/{{id}}.jpg">
                <img src="images/{{id}}t.jpg" border="0"/>
              </a>
            </xsl:otherwise>
          </xsl:choose>
        </td>
      </xsl:if>

      {5}

      <xsl:if test="$details = 'true'">
        <td class="value">
          <a href="details/{{id}}.html">
            <xsl:value-of select="/movies/metadata/field[@name='details']/@label"/>
          </a>
        </td>
      </xsl:if>

    </tr>
  </xsl:template>

  <xsl:template match="navigation">
    <div class="navigation" align="center">
      <xsl:if test="count(pagelink) > 1">
        <div class="navigationline">
          <xsl:for-each select="pagelink">
            <xsl:choose>
              <xsl:when test="@url!=''">
                <div class="navlink">
                  <a href="{{@url}}">
                    <xsl:value-of select="@pagenum"/>
                  </a>
                </div>
              </xsl:when>
              <xsl:otherwise>
                <div class="navlink" id="current">
                  <xsl:value-of select="@pagenum"/>
                </div>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="position()!=last()"></xsl:if>
          </xsl:for-each>
        </div>
        <div class="navigationline">
          <xsl:choose>
            <xsl:when test="firstlink/@url!=''">
              <div class="navlink">
                <a href="{{firstlink/@url}}">
                  <xsl:value-of select="/movies/metadata/field[@name='first']/@label"/>
                </a>
              </div>
            </xsl:when>
            <xsl:otherwise>
              <div class="navlink">
                <xsl:value-of select="/movies/metadata/field[@name='first']/@label"/>
              </div>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="prevlink/@url!=''">
              <div class="navlink">
                <a href="{{prevlink/@url}}">
                  <xsl:value-of select="/movies/metadata/field[@name='prev']/@label"/>
                </a>
              </div>
            </xsl:when>
            <xsl:otherwise>
              <div class="navlink">
                <xsl:value-of select="/movies/metadata/field[@name='prev']/@label"/>
              </div>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="nextlink/@url!=''">
              <div class="navlink">
                <a href="{{nextlink/@url}}">
                  <xsl:value-of select="/movies/metadata/field[@name='next']/@label"/>
                </a>
              </div>
            </xsl:when>
            <xsl:otherwise>
              <div class="navlink">
                <xsl:value-of select="/movies/metadata/field[@name='next']/@label"/>
              </div>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="lastlink/@url!=''">
              <div class="navlink">
                <a href="{{lastlink/@url}}">
                  <xsl:value-of select="/movies/metadata/field[@name='last']/@label"/>
                </a>
              </div>
            </xsl:when>
            <xsl:otherwise>
              <div class="navlink">
                <xsl:value-of select="/movies/metadata/field[@name='last']/@label"/>
              </div>
            </xsl:otherwise>
          </xsl:choose>
        </div>
      </xsl:if>
    </div>
  </xsl:template>

</xsl:stylesheet>

